<template>
	
		<view class="p-2 animated fast fadeIn">
			<view class="flex align-center justify-between">
				<!-- 头像 -->
				<view class="flex align-center">
					<image 
					lazy-load
					class="mr-2"
					:src="item.userpic" 
					style="height: 65rpx;width: 65rpx;"
					@click="openSpace"
					>
					</image>
					<view>
						<view class="font-sm" style="line-height: 1.2;">{{item.username}}</view>
						<text 
						class="font-small text-light-muted"
						style="line-height: 1;"
						>{{item.newstime|formateTime}}
						</text>
					</view>
				</view>
				<!-- 按钮 -->
				<view 
				class="flex justify-center align-center font-sm rounded bg-main animated"
				style="width: 90rpx;height: 50rpx;color: #ffffff;"
				hover-class="pulse"
				@click="follow"
				v-if="!item.isFollow"
				>
					关注</view>
			</view>
			<!-- 标题 -->
			<view class="m-1 font-md" style="font-weight: 500;" @click="openDetail">{{item.title}}</view>
			<slot>
				<!-- 图片 -->
				<image 
				v-if="item.titlepic"
				class="rounded w-100"
				lazy-load
				:src="item.titlepic" 
				style="height: 350rpx;"
				@click="openDetail"
				>
				</image>
			</slot>
			<view class="flex align-center">
				<view 
				class="flex-1 flex justify-center align-center animated faster" 
				hover-class="jello text-main" 
				@click="doSupport('support')" 
				:class="item.support.type==='support' ? 'text-main': ''">
					<text class="iconfont icon-dianzan2 mr-2"></text>
					<text>
						{{item.support.support_count == 0 ? '顶':item.support.support_count}}
					</text>
				</view>
				<view 
				class="flex-1 flex justify-center align-center animated faster" 
				hover-class="jello text-main" 
				@click="doSupport('unsupport')"
				:class="item.support.type==='unsupport' ? 'text-main': ''">
					<text class="iconfont icon-cai mr-2"></text>
					<text>
						{{item.support.unsupport_count == 0 ? '踩':item.support.unsupport_count}}
					</text>
				</view>
				<view class="flex-1 flex justify-center align-center animated faster" hover-class="jello text-main" @click="doComment">
					<text class="iconfont icon-pinglun2 mr-2"></text>
					<text>{{item.comment_count}}</text>
				</view>
				<view class="flex-1 flex justify-center align-center animated faster" hover-class="jello text-main" @click="doShare">
					<text class="iconfont icon-zhuanfa1 mr-2"></text>
					<text>{{item.share_num}}</text>
				</view>
			</view>
		</view>
</template>

<script>
	import $T from '@/common/time.js'
	export default{
		props:{
			item:{
				type:Object,
				required:true
			},
			index:{
				type:[String,Number]
			},
			isDetail: {
				type:Boolean,
				default:false
			}
		},
		filters: {
			formateTime(val) {
				return $T.gettime(val)
			}
		},
		methods:{
			// 打开个人空间
			openSpace() {
				uni.navigateTo({
					url:'/pages/user-space/user-space'
				})
			},
			// 关注用户
			follow() {
				this.checkAuth(() => {
					this.$emit('follow',this.index)
				})
			},
			// 打开文章详情
			openDetail() {
				// 如果是处于详情页 直接返回
				if (this.isDetail) return
				uni.navigateTo({
					url:'../../pages/detail/detail?detail=' + JSON.stringify(this.item)
				})
			},
			// 支持-反对
			doSupport(type) {
				this.$emit('doSupport',{
					type:type,
					index:this.index
				})
			},
			// 评论
			doComment() {
				if (!this.isDetail) {
					return this.openDetail()
				}
				this.$emit('doComment')
			},
			// 分享
			doShare() {
				if (!this.isDetail) {
					return this.openDetail()
				}
				this.$emit('doShare')
			}
		}
	}
</script>

<style>
</style>
